package gui5e;

/*
 * GUI class for processing
 * copyleft: m@w0rk 2012
 * u need: java 7, controlp5
 * still 2DO:
 * - autohide slider of panels
 * - smoother animation
 * - turn of autoupdate buttons
 * - checkbox class / radiobuttons class
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import processing.core.PApplet;
import gui5e.*;
import gui5e_modules.*;
import controlP5.Button;
import controlP5.ControlFont;
import controlP5.ControllerInterface;
import controlP5.DropdownList;
import controlP5.Group;
import controlP5.Textlabel;

public class GUI {
	private static PApplet parent;
	
	public static float sc = 5;
	public static float trrX = 0;
	public static float trrY = 0;
	
	public static Preferences gen; // general stuff
	public static Preferences lan; //languages
	public static Preferences sty; //styles
	
	public static ArrayList<ControllerInterface> deleteMe = new ArrayList<ControllerInterface>();
	// registering elements for translation module!
	@SuppressWarnings("rawtypes")
	public static Map<ControllerInterface, String> labels = new HashMap<ControllerInterface, String>();
	/*public static Map<String, Group> groupitems = new HashMap<String, Group>();
	public static ArrayList<DropdownList> dropdownlistitems = new ArrayList<DropdownList>();
	public static ArrayList<Button> buttonitems = new ArrayList<Button>();*/
	
	public static ArrayList<Module> eventListener = new ArrayList<Module>();
	public static final String PATH =  System.getProperty("user.home") + "/CAAD-APPS/CDE-0.1/";
	public static int innerWidth;
	public static int innerHeight;
	public static int innerTop;
	public static int innerLeft;
	public static int panelLeftWidth = 300;
	public static int panelRightWidth;
	public static int panelTopHeight;
	public static int panelBottomHeight;
	public static int PanelSpeed = 15;
	public static ControlFont fontA;
	public static boolean cp5_toUpperCase = true;
	public static int[] cp5_setPadding = {4,4};
	public static int cp5_setBarHeight = 14;
	public static int cp5_setWidth = 125;
	public static int[] background = {0,0,0,255}; 
	public static int[] backgroundPanel = {30,30,30,255}; // BTW: http://www.wackerart.de/rgbfarben.html
	public static int[] borderPanel = {30,30,30,255};
	public static int[] cp5_backgroundGroup = {150,50,50,255}; 
	public static int[] cp5_background = {150,50,50,255}; 
	public static int[] cp5_active = {150,50,50,255}; 
	public static int[] cp5_caption = {150,50,50,255}; 
	public static int[] cp5_foreground = {150,50,50,255}; 
	public static int[] cp5_value = {150,50,50,255}; 

	
	public GUI(PApplet p){
		parent = p;
		fontA= new ControlFont(p.createFont("Aurora Extended",8,false)); //font import
		// a more stylish fontface: PFont pfont = panel.parent_.createFont("Grixel Kyrou 9 Regular",8,false); // use true/false for smooth/no-smooth	
	}
	
	public static void styleList(DropdownList l_, String n_){
		  l_.getCaptionLabel().setFont(GUI.fontA)
		  	.toUpperCase(cp5_toUpperCase)
		  	.setPadding(cp5_setPadding[0],cp5_setPadding[1])
		  	;
		  l_.setBarHeight(cp5_setBarHeight)
		  	.setWidth(cp5_setWidth)
		  	;
		  // registering
		  if(labels.containsKey(l_) == false)  labels.put(l_, n_);
		}
	
	public static void styleLabel(Textlabel l_, String n_){
		  l_.getCaptionLabel().setFont(GUI.fontA)
		  	.toUpperCase(cp5_toUpperCase)
		  	.setPadding(cp5_setPadding[0],cp5_setPadding[1])
		  	;
		  l_.setHeight(cp5_setBarHeight)
		  	.setWidth(cp5_setWidth)
		  	;
		  // registering
		  if(labels.containsKey(l_) == false) labels.put(l_, n_);
		}
		
	public static void styleButton(Button b_, String n_, String f_){
		  b_.getCaptionLabel().setFont(GUI.fontA)
		  	.toUpperCase(cp5_toUpperCase)
		  	.setPadding(cp5_setPadding[0],cp5_setPadding[1])
		  	;
		  b_.setHeight(cp5_setBarHeight)
		  	.setWidth(b_.getCaptionLabel().getText().length()*8)
		  	;
		  switch(f_){ // float direction
			  case "right": b_.setPosition((panelLeftWidth - b_.getWidth() - 30), b_.getPosition().y); break;
			  case "keep": if(b_.getPosition().x > 10) b_.setPosition((panelLeftWidth - b_.getWidth() - 30), b_.getPosition().y); break;
			  case "left" : b_.setPosition(10, b_.getPosition().y); break;
		  }
		  // registering
		  if(labels.containsKey(b_) == false)  labels.put(b_, n_);
		}
	
	public static void styleGroup(Group g_, String n_){
		  g_.getCaptionLabel().setFont(GUI.fontA)
		  	.toUpperCase(cp5_toUpperCase)
		  	.setPadding(cp5_setPadding[0],cp5_setPadding[1])
		  	;
		  g_.setHeight(cp5_setBarHeight)
		  	//.setBackgroundHeight(150) // comment out for individual group height!
		  	.setBackgroundColor(parent.color(GUI.cp5_backgroundGroup[0],GUI.cp5_backgroundGroup[1],GUI.cp5_backgroundGroup[2],GUI.cp5_backgroundGroup[3]))  
		  	.setWidth(GUI.panelLeftWidth - 20)
		  	;
		  // registering
		  //if(groupitems.containsValue(g_) == false)  groupitems.put(g_.getName(), g_);
		  if(labels.containsKey(g_) == false)  labels.put(g_, n_);
	}
	
	public static String label(String w_){
		return GUI.lan.get(w_);
	}
	
}
